<div class="layui-fluid" lay-title="表单组合">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" method="post" lay-filter="form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">上级菜单栏</label>
                    <div class="layui-input-block">
                        <label>
                            <select name="parent_id" lay-verify="required">
                                [^if .option|len ^]
                                [^ .option|str2html ^]
                                [^else^]
                                <option value="0" selected>作为一级菜单</option>
                                [^end^]
                            </select>
                        </label>
                    </div>
                </div>
                <input type="hidden" name="id"
                       value="[^ .data.Id ^]"
                >
                <div class="layui-form-item">
                    <label class="layui-form-label">菜单名称</label>
                    <div class="layui-input-block">
                        <label>
                            <input type="text" name="name" lay-verify="required|max30" placeholder="请输入菜单名称"
                                   autocomplete="off" value="[^ .data.Name ^]"
                                   class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">控制器</label>
                    <div class="layui-input-block">
                        <label>
                            <input type="text" name="controller" lay-verify="required|max30" placeholder="请输入控制器名"
                                   autocomplete="off" value="[^ .data.Controller ^]"
                                   class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">方法</label>
                    <div class="layui-input-block">
                        <label>
                            <input type="text" name="action" lay-verify="required|max30" placeholder="请输入方法名"
                                   autocomplete="off" value="[^ .data.Action ^]"
                                   class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">参数</label>
                    <div class="layui-input-block">
                        <label>
                            <input type="text" name="param" placeholder="请输入参数" lay-verify="max30"
                                   autocomplete="off" value="[^ .data.Param ^]"
                                   class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图标</label>
                    <div class="layui-input-block">
                        <label>
                            <input type="text" name="icon" placeholder="请输入" lay-verify="max50"
                                   autocomplete="off" value="[^ .data.Icon ^]"
                                   class="layui-input">
                        </label>
                        <div class="layui-inline">
                            <div class="layui-form-mid layui-word-aux">
                                <button class="layui-btn layui-btn-sm layui-btn-primary" lay-popup="/sys/icon">选择
                                </button>
                                请选择图标
                            </div>
                        </div>
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <label>
                            <textarea name="remark" placeholder="请输入内容" lay-verify="max250"
                                      class="layui-textarea">[^ .data.Remark ^]</textarea>
                        </label>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">开启状态</label>
                    <div class="layui-input-block">
                        <label>
                            <select name="status">
                                [^ if .isEdit ^]
                                [^ if eq .data.Status 0 ^]
                                <option value="1">在左侧菜单展示</option>
                                <option value="0" selected>在左侧菜单隐藏</option>
                                [^ else ^]
                                <option value="1" selected>在左侧菜单展示</option>
                                <option value="0">在左侧菜单隐藏</option>
                                [^ end ^]
                                [^ else ^]
                                <option value="1" selected>在左侧菜单展示</option>
                                <option value="0">在左侧菜单隐藏</option>
                                [^ end ^]
                            </select>
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <label>
                            <select name="type">
                                [^ if .isEdit ^]
                                <option value="1"
                                        [^ if eq .data.Type 1 ^]
                                        selected
                                        [^ end ^]
                                >有界面可访问菜单
                                </option>
                                <option value="0"
                                        [^ if eq .data.Type 2 ^]
                                        selected
                                        [^ end ^]
                                >无界面可访问菜单
                                </option>
                                <option value="0"
                                        [^ if eq .data.Type 0 ^]
                                        selected
                                        [^ end ^]
                                >只作为菜单
                                </option>
                                [^ else ^]
                                <option value="1" selected>有界面可访问菜单</option>
                                <option value="2">无界面可访问菜单</option>
                                <option value="0">只作为菜单</option>
                                [^ end ^]

                            </select>
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">菜单所属模块</label>
                    <div class="layui-input-block">
                        <label>
                            <select name="module_belong">
                                <option value="1"
                                        [^ if eq .data.ModuleBelong 1 ^]
                                        selected
                                        [^ end ^]
                                >默认
                                </option>
                            </select>
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <label>
                            <input type="text" name="list_order" placeholder="请输入排序" autocomplete="off"
                                   class="layui-input" lay-verify="NonNegativeInteger"
                                   [^ if .data.ListOrder ^]
                                   value="[^ .data.ListOrder ^]"
                                   [^ else ^]
                                   value="100"
                                   [^ end ^]>
                        </label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="form-group-submit">
                            <i style="display: none"
                               class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
                            立即提交
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    layui.use(['admin', 'form'], function () {
        var $ = layui.$
            , admin = layui.admin
            , element = layui.element
            , layer = layui.layer
            , form = layui.form;
        form.render(null, 'form-group');
        var layUrl = $(this)[0].view.containerBody.find(".nepadmin-tabs-item").attr("lay-url")
        var loading = $(this).find('.layui-icon');
        if (loading.is(":visible")) return;
        //验证字段
        form.verify({
            max30: function (value, item) {
                if (value.length > 30) {
                    return "最多30个字符"
                }
            },
            max50: function (value, item) {
                if (value.length > 50) {
                    return "最多50个字符"
                }
            },
            max250: function (value, item) {
                if (value.length > 250) {
                    return "最多250个字符"
                }
            },
            NonNegativeInteger: [
                /^\d+$/
                , '必须为非负正整数'
            ],
        });
        loading.show();
        form.on('submit(form-group-submit)', function (data) {
            //想后台发送请求进行登录操作
            admin.post({
                api: 'addMenu',
                type: "post",
                data: data.field,
                success: function (res) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 800 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        admin.submitToJump(layUrl, res.url)
                    });
                },
                error: function (res) {
                    layer.msg(res.msg, {
                        icon: 2,
                        time: 800 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        loading.hide();
                    });

                },
                complete: function () {
                    //loading.hide();
                }
            });
            return false;
        });
    });
</script>